package com.jvxb.manage.livable.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jvxb.common.web.RespMsg;
import com.jvxb.manage.livable.vo.MySQLSlowLogQueryVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author jvxb
 * @since 2022-02-14
 */
@RestController
@RequestMapping("/dbLog/v1")
public class DbLogController {

    @GetMapping("/getMySQLSlowLogByHostAndPort")
    public RespMsg getMySQLSlowLogByHostAndPort(MySQLSlowLogQueryVo slowLogQueryVo) {
        IPage logPage = new Page<>(slowLogQueryVo.getCurrent(), slowLogQueryVo.getSize());
        logPage.setTotal(100);
        List<Map> content = JSONObject.parseArray("[\n" +
                "\t\t{\n" +
                "\t\t\t\"id\": \"67452526-73ab-4cff-89bc-591befbcc0c1\",\n" +
                "\t\t\t\"messageDate\": \"2022-02-16 08:56:41\",\n" +
                "\t\t\t\"mysqlHost\": \"10.192.28.132\",\n" +
                "\t\t\t\"mysqlPort\": \"11004\",\n" +
                "\t\t\t\"hostPort\": \"10.192.28.132:11004\",\n" +
                "\t\t\t\"dbUser\": \"rw_vologda\",\n" +
                "\t\t\t\"dbClientHost\": \"10.102.37.201\",\n" +
                "\t\t\t\"queryTime\": 3.738,\n" +
                "\t\t\t\"lockTime\": 0.024,\n" +
                "\t\t\t\"rowsSent\": 1,\n" +
                "\t\t\t\"rowsExamined\": 2004884,\n" +
                "\t\t\t\"timestamp\": 1644972991262,\n" +
                "\t\t\t\"sqlStr\": \"SELECT * FROM `standby_sync_log`  WHERE (couple_id = 182) AND (master_node_id = 'e678d71eab63e1f66f3894de777545a6ffc87c99' or slave_node_id = 'e678d71eab63e1f66f3894de777545a6ffc87c99' or slave1_node_id = 'e678d71eab63e1f66f3894de777545a6ffc87c99') AND (status = 0);\\n\",\n" +
                "\t\t\t\"sqlType\": \"select\",\n" +
                "\t\t\t\"sqlFinger\": \"D82508925BE356EA\",\n" +
                "\t\t\t\"sqlFingerPrint\": \"SELECT * FROM `standby_sync_log`  WHERE (couple_id = 182) AND (master_node_id = 'e678d71eab63e1f66f3894de777545a6ffc87c99' or slave_node_id = 'e678d71eab63e1f66f3894de777545a6ffc87c99' or slave1_node_id = 'e678d71eab63e1f66f3894de777545a6ffc87c99') AND (status = 0); \",\n" +
                "\t\t\t\"sqlAdvisor\": \"{}\",\n" +
                "\t\t\t\"logType\": \"mysqlSlow\",\n" +
                "\t\t\t\"dbname\": \"tiver\",\n" +
                "\t\t\t\"serviceName\": \"vologda\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"id\": \"c9184e45-b781-4059-a121-b0b02eb593bd\",\n" +
                "\t\t\t\"messageDate\": \"2022-02-16 08:56:36\",\n" +
                "\t\t\t\"mysqlHost\": \"10.192.28.132\",\n" +
                "\t\t\t\"mysqlPort\": \"11004\",\n" +
                "\t\t\t\"hostPort\": \"10.192.28.132:11004\",\n" +
                "\t\t\t\"dbUser\": \"rw_vologda\",\n" +
                "\t\t\t\"dbClientHost\": \"10.102.37.201\",\n" +
                "\t\t\t\"queryTime\": 4.347,\n" +
                "\t\t\t\"lockTime\": 0.025,\n" +
                "\t\t\t\"rowsSent\": 1,\n" +
                "\t\t\t\"rowsExamined\": 2004884,\n" +
                "\t\t\t\"timestamp\": 1644972982653,\n" +
                "\t\t\t\"sqlStr\": \"SELECT * FROM `standby_sync_log`  WHERE (couple_id = 182) AND (master_node_id = '5c06140b2ee4db1930c3a4d290151957d85c0a3a' or slave_node_id = '5c06140b2ee4db1930c3a4d290151957d85c0a3a' or slave1_node_id = '5c06140b2ee4db1930c3a4d290151957d85c0a3a') AND (status = 0 or status = 2);\",\n" +
                "\t\t\t\"sqlType\": \"select\",\n" +
                "\t\t\t\"sqlFinger\": \"17BBB182C8841986\",\n" +
                "\t\t\t\"sqlFingerPrint\": \"SELECT * FROM `standby_sync_log`  WHERE (couple_id = 182) AND (master_node_id = '5c06140b2ee4db1930c3a4d290151957d85c0a3a' or slave_node_id = '5c06140b2ee4db1930c3a4d290151957d85c0a3a' or slave1_node_id = '5c06140b2ee4db1930c3a4d290151957d85c0a3a') AND (status = 0 or status = 2);\",\n" +
                "\t\t\t\"sqlAdvisor\": \"{}\",\n" +
                "\t\t\t\"logType\": \"mysqlSlow\",\n" +
                "\t\t\t\"dbname\": \"tiver\",\n" +
                "\t\t\t\"serviceName\": \"vologda\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"id\": \"51c29d35-d309-45b1-91ab-7dc50abc96eb\",\n" +
                "\t\t\t\"messageDate\": \"2022-02-16 08:56:29\",\n" +
                "\t\t\t\"mysqlHost\": \"10.192.28.132\",\n" +
                "\t\t\t\"mysqlPort\": \"11004\",\n" +
                "\t\t\t\"hostPort\": \"10.192.28.132:11004\",\n" +
                "\t\t\t\"dbUser\": \"rw_vologda\",\n" +
                "\t\t\t\"dbClientHost\": \"10.102.37.201\",\n" +
                "\t\t\t\"queryTime\": 3.805,\n" +
                "\t\t\t\"lockTime\": 0.025,\n" +
                "\t\t\t\"rowsSent\": 1,\n" +
                "\t\t\t\"rowsExamined\": 2004883,\n" +
                "\t\t\t\"timestamp\": 1644972979195,\n" +
                "\t\t\t\"sqlStr\": \"SELECT * FROM `standby_sync_log`  WHERE (couple_id = 182) AND (master_node_id = '29b02cfaabc3cbe81990e6df7824c8a1dd73d674' or slave_node_id = '29b02cfaabc3cbe81990e6df7824c8a1dd73d674' or slave1_node_id = '29b02cfaabc3cbe81990e6df7824c8a1dd73d674') AND (status = 0);\",\n" +
                "\t\t\t\"sqlType\": \"select\",\n" +
                "\t\t\t\"sqlFinger\": \"D82508925BE356EA\",\n" +
                "\t\t\t\"sqlFingerPrint\": \"SELECT * FROM `standby_sync_log`  WHERE (couple_id = 182) AND (master_node_id = '29b02cfaabc3cbe81990e6df7824c8a1dd73d674' or slave_node_id = '29b02cfaabc3cbe81990e6df7824c8a1dd73d674' or slave1_node_id = '29b02cfaabc3cbe81990e6df7824c8a1dd73d674') AND (status = 0);\",\n" +
                "\t\t\t\"sqlAdvisor\": \"{}\",\n" +
                "\t\t\t\"logType\": \"mysqlSlow\",\n" +
                "\t\t\t\"dbname\": \"tiver\",\n" +
                "\t\t\t\"serviceName\": \"vologda\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"id\": \"3ef212af-c03b-4f94-9cc1-bb2a56047ce8\",\n" +
                "\t\t\t\"messageDate\": \"2022-02-16 08:56:22\",\n" +
                "\t\t\t\"mysqlHost\": \"10.192.28.132\",\n" +
                "\t\t\t\"mysqlPort\": \"11004\",\n" +
                "\t\t\t\"hostPort\": \"10.192.28.132:11004\",\n" +
                "\t\t\t\"dbUser\": \"rw_vologda\",\n" +
                "\t\t\t\"dbClientHost\": \"10.102.37.201\",\n" +
                "\t\t\t\"queryTime\": 4.432,\n" +
                "\t\t\t\"lockTime\": 0.025,\n" +
                "\t\t\t\"rowsSent\": 1,\n" +
                "\t\t\t\"rowsExamined\": 2004883,\n" +
                "\t\t\t\"timestamp\": 1644972970569,\n" +
                "\t\t\t\"sqlStr\": \"SELECT * FROM `standby_sync_log`  WHERE (couple_id = 182) AND (master_node_id = '134f1089ec0d105e05986ceccc402c5e107c07ef' or slave_node_id = '134f1089ec0d105e05986ceccc402c5e107c07ef' or slave1_node_id = '134f1089ec0d105e05986ceccc402c5e107c07ef') AND (status = 0 or status = 2);\",\n" +
                "\t\t\t\"sqlType\": \"select\",\n" +
                "\t\t\t\"sqlFinger\": \"17BBB182C8841986\",\n" +
                "\t\t\t\"sqlFingerPrint\": \"SELECT * FROM `standby_sync_log`  WHERE (couple_id = 182) AND (master_node_id = '134f1089ec0d105e05986ceccc402c5e107c07ef' or slave_node_id = '134f1089ec0d105e05986ceccc402c5e107c07ef' or slave1_node_id = '134f1089ec0d105e05986ceccc402c5e107c07ef') AND (status = 0 or status = 2);\",\n" +
                "\t\t\t\"sqlAdvisor\": \"{}\",\n" +
                "\t\t\t\"logType\": \"mysqlSlow\",\n" +
                "\t\t\t\"dbname\": \"tiver\",\n" +
                "\t\t\t\"serviceName\": \"vologda\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"id\": \"afdfb83c-059d-46ee-97f6-2c63ce4a3a6f\",\n" +
                "\t\t\t\"messageDate\": \"2022-02-16 08:56:17\",\n" +
                "\t\t\t\"mysqlHost\": \"10.192.28.132\",\n" +
                "\t\t\t\"mysqlPort\": \"11004\",\n" +
                "\t\t\t\"hostPort\": \"10.192.28.132:11004\",\n" +
                "\t\t\t\"dbUser\": \"rw_vologda\",\n" +
                "\t\t\t\"dbClientHost\": \"10.102.37.201\",\n" +
                "\t\t\t\"queryTime\": 3.766,\n" +
                "\t\t\t\"lockTime\": 0.049,\n" +
                "\t\t\t\"rowsSent\": 1,\n" +
                "\t\t\t\"rowsExamined\": 2004882,\n" +
                "\t\t\t\"timestamp\": 1644972967235,\n" +
                "\t\t\t\"sqlStr\": \"SELECT * FROM `standby_sync_log`  WHERE (couple_id = 182) AND (master_node_id = '47d3afc9be361208e6d3502cb9269fc081bdfc20' or slave_node_id = '47d3afc9be361208e6d3502cb9269fc081bdfc20' or slave1_node_id = '47d3afc9be361208e6d3502cb9269fc081bdfc20') AND (status = 0);\\n\",\n" +
                "\t\t\t\"sqlType\": \"select\",\n" +
                "\t\t\t\"sqlFinger\": \"D82508925BE356EA\",\n" +
                "\t\t\t\"sqlFingerPrint\": \"SELECT * FROM `standby_sync_log`  WHERE (couple_id = 182) AND (master_node_id = '47d3afc9be361208e6d3502cb9269fc081bdfc20' or slave_node_id = '47d3afc9be361208e6d3502cb9269fc081bdfc20' or slave1_node_id = '47d3afc9be361208e6d3502cb9269fc081bdfc20') AND (status = 0); \",\n" +
                "\t\t\t\"sqlAdvisor\": \"{}\",\n" +
                "\t\t\t\"logType\": \"mysqlSlow\",\n" +
                "\t\t\t\"dbname\": \"tiver\",\n" +
                "\t\t\t\"serviceName\": \"vologda\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"id\": \"7a7aca97-2cb9-45f3-a804-a72fcdb4c920\",\n" +
                "\t\t\t\"messageDate\": \"2022-02-16 08:56:12\",\n" +
                "\t\t\t\"mysqlHost\": \"10.192.28.132\",\n" +
                "\t\t\t\"mysqlPort\": \"11004\",\n" +
                "\t\t\t\"hostPort\": \"10.192.28.132:11004\",\n" +
                "\t\t\t\"dbUser\": \"dbcmdb_rw\",\n" +
                "\t\t\t\"dbClientHost\": \"10.102.162.96\",\n" +
                "\t\t\t\"queryTime\": 3.681,\n" +
                "\t\t\t\"lockTime\": 0.037,\n" +
                "\t\t\t\"rowsSent\": 1,\n" +
                "\t\t\t\"rowsExamined\": 14582693,\n" +
                "\t\t\t\"timestamp\": 1644972959320,\n" +
                "\t\t\t\"sqlStr\": \"SELECT MAX(`create_time`) FROM `project_resource_detail_info`;\",\n" +
                "\t\t\t\"sqlType\": \"select\",\n" +
                "\t\t\t\"sqlFinger\": \"BE78042D65D33B67\",\n" +
                "\t\t\t\"sqlFingerPrint\": \"SELECT MAX(`create_time`) FROM `project_resource_detail_info`;\",\n" +
                "\t\t\t\"sqlAdvisor\": \"{}\",\n" +
                "\t\t\t\"logType\": \"mysqlSlow\",\n" +
                "\t\t\t\"dbname\": \"dbcmdb\",\n" +
                "\t\t\t\"serviceName\": \"voronezh\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"id\": \"9420a22e-fc7c-4c10-a655-ed7d5c6c575b\",\n" +
                "\t\t\t\"messageDate\": \"2022-02-16 08:56:08\",\n" +
                "\t\t\t\"mysqlHost\": \"10.192.28.132\",\n" +
                "\t\t\t\"mysqlPort\": \"11004\",\n" +
                "\t\t\t\"hostPort\": \"10.192.28.132:11004\",\n" +
                "\t\t\t\"dbUser\": \"rw_vologda\",\n" +
                "\t\t\t\"dbClientHost\": \"10.102.37.201\",\n" +
                "\t\t\t\"queryTime\": 4.426,\n" +
                "\t\t\t\"lockTime\": 0.028,\n" +
                "\t\t\t\"rowsSent\": 1,\n" +
                "\t\t\t\"rowsExamined\": 2004882,\n" +
                "\t\t\t\"timestamp\": 1644972958575,\n" +
                "\t\t\t\"sqlStr\": \"SELECT * FROM `standby_sync_log`  WHERE (couple_id = 182) AND (master_node_id = '370c68e82e3d6f6825139253c2da67e802ba6d3c' or slave_node_id = '370c68e82e3d6f6825139253c2da67e802ba6d3c' or slave1_node_id = '370c68e82e3d6f6825139253c2da67e802ba6d3c') AND (status = 0 or status = 2);\",\n" +
                "\t\t\t\"sqlType\": \"select\",\n" +
                "\t\t\t\"sqlFinger\": \"17BBB182C8841986\",\n" +
                "\t\t\t\"sqlFingerPrint\": \"SELECT * FROM `standby_sync_log`  WHERE (couple_id = 182) AND (master_node_id = '370c68e82e3d6f6825139253c2da67e802ba6d3c' or slave_node_id = '370c68e82e3d6f6825139253c2da67e802ba6d3c' or slave1_node_id = '370c68e82e3d6f6825139253c2da67e802ba6d3c') AND (status = 0 or status = 2);\",\n" +
                "\t\t\t\"sqlAdvisor\": \"{}\",\n" +
                "\t\t\t\"logType\": \"mysqlSlow\",\n" +
                "\t\t\t\"dbname\": \"tiver\",\n" +
                "\t\t\t\"serviceName\": \"vologda\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"id\": \"e9a4d619-2a57-4fa9-9cb0-695364b83684\",\n" +
                "\t\t\t\"messageDate\": \"2022-02-16 08:56:07\",\n" +
                "\t\t\t\"mysqlHost\": \"10.192.28.132\",\n" +
                "\t\t\t\"mysqlPort\": \"11004\",\n" +
                "\t\t\t\"hostPort\": \"10.192.28.132:11004\",\n" +
                "\t\t\t\"dbUser\": \"rw_vologda\",\n" +
                "\t\t\t\"dbClientHost\": \"10.102.37.201\",\n" +
                "\t\t\t\"queryTime\": 3.693,\n" +
                "\t\t\t\"lockTime\": 0.038,\n" +
                "\t\t\t\"rowsSent\": 1,\n" +
                "\t\t\t\"rowsExamined\": 2004881,\n" +
                "\t\t\t\"timestamp\": 1644972955307,\n" +
                "\t\t\t\"sqlStr\": \"SELECT * FROM `standby_sync_log`  WHERE (couple_id = 182) AND (master_node_id = 'e678d71eab63e1f66f3894de777545a6ffc87c99' or slave_node_id = 'e678d71eab63e1f66f3894de777545a6ffc87c99' or slave1_node_id = 'e678d71eab63e1f66f3894de777545a6ffc87c99') AND (status = 0);\\n\",\n" +
                "\t\t\t\"sqlType\": \"select\",\n" +
                "\t\t\t\"sqlFinger\": \"D82508925BE356EA\",\n" +
                "\t\t\t\"sqlFingerPrint\": \"SELECT * FROM `standby_sync_log`  WHERE (couple_id = 182) AND (master_node_id = 'e678d71eab63e1f66f3894de777545a6ffc87c99' or slave_node_id = 'e678d71eab63e1f66f3894de777545a6ffc87c99' or slave1_node_id = 'e678d71eab63e1f66f3894de777545a6ffc87c99') AND (status = 0); \",\n" +
                "\t\t\t\"sqlAdvisor\": \"{}\",\n" +
                "\t\t\t\"logType\": \"mysqlSlow\",\n" +
                "\t\t\t\"dbname\": \"tiver\",\n" +
                "\t\t\t\"serviceName\": \"vologda\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"id\": \"2f558170-7afd-489d-8f2c-ec6ed7e567fb\",\n" +
                "\t\t\t\"messageDate\": \"2022-02-16 08:55:57\",\n" +
                "\t\t\t\"mysqlHost\": \"10.192.28.132\",\n" +
                "\t\t\t\"mysqlPort\": \"11004\",\n" +
                "\t\t\t\"hostPort\": \"10.192.28.132:11004\",\n" +
                "\t\t\t\"dbUser\": \"rw_vologda\",\n" +
                "\t\t\t\"dbClientHost\": \"10.102.37.201\",\n" +
                "\t\t\t\"queryTime\": 3.974,\n" +
                "\t\t\t\"lockTime\": 0.029,\n" +
                "\t\t\t\"rowsSent\": 1,\n" +
                "\t\t\t\"rowsExamined\": 2004881,\n" +
                "\t\t\t\"timestamp\": 1644972947027,\n" +
                "\t\t\t\"sqlStr\": \"SELECT * FROM `standby_sync_log`  WHERE (couple_id = 182) AND (master_node_id = '5c06140b2ee4db1930c3a4d290151957d85c0a3a' or slave_node_id = '5c06140b2ee4db1930c3a4d290151957d85c0a3a' or slave1_node_id = '5c06140b2ee4db1930c3a4d290151957d85c0a3a') AND (status = 0 or status = 2);\",\n" +
                "\t\t\t\"sqlType\": \"select\",\n" +
                "\t\t\t\"sqlFinger\": \"17BBB182C8841986\",\n" +
                "\t\t\t\"sqlFingerPrint\": \"SELECT * FROM `standby_sync_log`  WHERE (couple_id = 182) AND (master_node_id = '5c06140b2ee4db1930c3a4d290151957d85c0a3a' or slave_node_id = '5c06140b2ee4db1930c3a4d290151957d85c0a3a' or slave1_node_id = '5c06140b2ee4db1930c3a4d290151957d85c0a3a') AND (status = 0 or status = 2);\",\n" +
                "\t\t\t\"sqlAdvisor\": \"{}\",\n" +
                "\t\t\t\"logType\": \"mysqlSlow\",\n" +
                "\t\t\t\"dbname\": \"tiver\",\n" +
                "\t\t\t\"serviceName\": \"vologda\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"id\": \"832937f2-7151-4d91-971b-54147c0b17b2\",\n" +
                "\t\t\t\"messageDate\": \"2022-02-16 08:55:52\",\n" +
                "\t\t\t\"mysqlHost\": \"10.192.28.132\",\n" +
                "\t\t\t\"mysqlPort\": \"11004\",\n" +
                "\t\t\t\"hostPort\": \"10.192.28.132:11004\",\n" +
                "\t\t\t\"dbUser\": \"rw_vologda\",\n" +
                "\t\t\t\"dbClientHost\": \"10.102.37.201\",\n" +
                "\t\t\t\"queryTime\": 3.837,\n" +
                "\t\t\t\"lockTime\": 0.028,\n" +
                "\t\t\t\"rowsSent\": 1,\n" +
                "\t\t\t\"rowsExamined\": 2004880,\n" +
                "\t\t\t\"timestamp\": 1644972943163,\n" +
                "\t\t\t\"sqlStr\": \"SELECT * FROM `standby_sync_log`  WHERE (couple_id = 182) AND (master_node_id = '29b02cfaabc3cbe81990e6df7824c8a1dd73d674' or slave_node_id = '29b02cfaabc3cbe81990e6df7824c8a1dd73d674' or slave1_node_id = '29b02cfaabc3cbe81990e6df7824c8a1dd73d674') AND (status = 0);\\n\",\n" +
                "\t\t\t\"sqlType\": \"select\",\n" +
                "\t\t\t\"sqlFinger\": \"D82508925BE356EA\",\n" +
                "\t\t\t\"sqlFingerPrint\": \"SELECT * FROM `standby_sync_log`  WHERE (couple_id = 182) AND (master_node_id = '29b02cfaabc3cbe81990e6df7824c8a1dd73d674' or slave_node_id = '29b02cfaabc3cbe81990e6df7824c8a1dd73d674' or slave1_node_id = '29b02cfaabc3cbe81990e6df7824c8a1dd73d674') AND (status = 0); \",\n" +
                "\t\t\t\"sqlAdvisor\": \"{}\",\n" +
                "\t\t\t\"logType\": \"mysqlSlow\",\n" +
                "\t\t\t\"dbname\": \"tiver\",\n" +
                "\t\t\t\"serviceName\": \"vologda\"\n" +
                "\t\t}\n" +
                "\t]", Map.class);
        logPage.setRecords(content);
        return RespMsg.ok(logPage);
    }

}
